#pragma once
#include<iostream>
#include<vector>
#include<string>
#include"./oj_mode.hpp"

#include"ctemplate/template.h"

namespace NS_VIEW
{
    using namespace NS_MODEL;
    const std::string template_path="./template_html/";
    class view 
    {
        public:
            view(){}
            ~view(){}
        public:
            bool ExpandAllHtml(std::vector<Question>& questions,std::string*html)
            {
                //1.形成路径
                std::string src_html=template_path+"all_questions.html";
                //2.形成字典
                ctemplate::TemplateDictionary root("all_questions");
                for(auto&ques : questions)
                {
                    ctemplate::TemplateDictionary *sub=root.AddSectionDictionary("question_list");
                    sub->SetValue("number",ques.number);
                    sub->SetValue("title",ques.title);
                    sub->SetValue("star",ques.star);
                }
                //3.获取被渲染的对象
                ctemplate::Template*tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

                //渲染
                tpl->Expand(html,&root);
                return true;
            }

            bool ExpandOneHtml(struct Question& question,std::string *html)
            {
                //1.形成路径
                std::string src_html=template_path+"one_question.html";
                //2.形成字典
                ctemplate::TemplateDictionary root("one_question");
                root.SetValue("number",question.number);
                root.SetValue("title",question.title);
                root.SetValue("star",question.star);
                root.SetValue("desc",question.desc);
                root.SetValue("header",question.header);

                //3.获取被渲染对象
                ctemplate::Template*tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
                
                //4.渲染
                tpl->Expand(html,&root);

                return true;
            }
    };

}
